#encoding:utf-8

import urllib2

url='https://www.baidu.com/'

headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
}


#创建请求对象

res = urllib2.Request(url,headers=headers)

print res.get_full_url() #获取完整的url
print res.get_method() #获取请求方法
print res.get_header("User-Agent")
print res.get_host() #获取host名称 不包含协议
print res.get_type() #获取协议名称
res.add_header("Connection","keep-alive")
print res.get_header("Connection")

